import { AlarmType } from '../../../constants/alarm';

/**生成报警类型下拉列表可选数据*/
export function generateAlarmTypeSelectorData() {
  const result = [{ value: '', label: '全部' }];
  Object.values(AlarmType).forEach(type => {
    result.push({ value: type, label: getAlarmTypeDisplay(type) });
  });

  return result;
}

/**
 * 获取报警类型显示信息
 * @param {string} alarm 报警类型
 */
export function getAlarmTypeDisplay(alarm) {
  switch (alarm) {
    case AlarmType.None:
      return '不报警';
    case AlarmType.Web:
      return '网页';
    case AlarmType.MP:
      return '公众号/小程序';
    case AlarmType.Sms:
      return '短信';
    case AlarmType.Mobile:
      return '电话';
    default:
      return '未知系统类型';
  }
}

/**
 * 校验表单是否合法
 * @param {object} from 表单信息
 */
export function validateForm(form) {
  if (!form.name) return '请输入报警规则名称';
  if (!form.alarmMethod) return '请选择报警比较方法';
  if (!form.parameterId) return '请选择设备参数';
  if (!form.alertThreshold) return '请选择预警阈值';
  if (!form.alarmThreshold) return '请选择报警阈值';
}

const ActiveList = {
  activeTrue: true,
  activeFalse: false
};

export function getActiveSelector() {
  const result = [];
  Object.values(ActiveList).forEach(active => {
    result.push({ value: active, label: getActiveDisplay(active) });
  });
  return result;
}

export function getActiveDisplay(active) {
  switch (active) {
    case ActiveList.activeTrue:
      return '启用';
    case ActiveList.activeFalse:
      return '不启用';
    default:
      return '未知';
  }
}

export function getActiveColor(active) {
  switch (active) {
    case ActiveList.activeTrue:
      return '#07c160';
    case ActiveList.activeFalse:
      return '#fa5151';
    default:
      return '#fff';
  }
}
